package com.util;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;

public class MyMapAdapter extends XmlAdapter<Object, Object> {

	@Override
	public Map unmarshal(Object v) throws Exception {
//		ElementNSImpl s = (ElementNSImpl)v;
		Node node = (Node)v;
//		System.out.println("Object: " + v);
		String name = node.getLocalName();

//		node.segetAttributes();
		HashMap map = new HashMap<String,String>();

		NodeList l = node.getChildNodes();
		int m = l.getLength();
		for(int x=0; x<m; x++){
			Node sn = l.item(x);
			String snn = sn.getLocalName();
			short type = sn.getNodeType();
			Object sno = sn.getTextContent();

			map.put(snn, sno);
		}
		// TODO Auto-generated method stub
//		System.out.println("Object: " + v);
//		System.out.println("Object: " + v.getClass());
//		System.out.println("Object: " + v.hashCode());
		
		return map;
	}

	@Override
	public Object marshal(Object v) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}


}
